package cj.web.admin.dao;
/*
 *  
 *  
*/
import java.util.List;
import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;
import cj.web.admin.domain.KDCard;

/**
 * 
 * @author 
 *
 */
@DAO
public interface KDCardDAO{
	
	@SQL("SELECT * FROM KDCard WHERE deleteFlag=1 #if(:t.cardNum!=''){ and cardNum like '%##(:t.cardNum)%' } ORDER BY cardNum DESC LIMIT :t.start,:t.length ")
    List<KDCard> query(@SQLParam("t") KDCard kDCard);
	
	@SQL("SELECT count(*) FROM KDCard WHERE deleteFlag=1 #if(:t.cardNum!=''){ and cardNum like '%##(:t.cardNum)%' } ")
    int querySize(@SQLParam("t") KDCard kDCard);
    
    @SQL("select * from KDCard where id=:1")
    KDCard queryById(int id);
    
    @SQL("INSERT INTO KDCard ("
			        		+ "cardNum,"
			        		+ "cardPwd,"
			        		+ "status,"
			        		+ "memo,"
			        		+ "deleteFlag,"
			        		+ "billAmount,"
			        		+ "paperCardName,"
			        		+ "paperName,"
			        		+ "inputBeginAt,"
			        		+ "inputEndAt,"
			        		+ "months,"
			        		+ "beginAt,"
			        		+ "endAt,"
			        		+ "createUser,"
			        		+ "createAt,"
			        		+ "updateUser,"
			        		+ "updateAt"
							+") VALUES ("
							+ ":t.cardNum,"
							+ ":t.cardPwd,"
							+ ":t.status,"
							+ ":t.memo,"
							+ ":t.deleteFlag,"
							+ ":t.billAmount,"
							+ ":t.paperCardName,"
							+ ":t.paperName,"
							+ ":t.inputBeginAt,"
							+ ":t.inputEndAt,"
							+ ":t.months,"
							+ ":t.beginAt,"
							+ ":t.endAt,"
							+ ":t.createUser,"
							+ "now(),"
							+ ":t.updateUser,"
							+ "now()"
					+")")
    void create(@SQLParam("t") KDCard kDCard);
	
	@SQL("UPDATE KDCard SET "
		        + "cardNum=:t.cardNum,"
		        + "cardPwd=:t.cardPwd,"
		        + "status=:t.status,"
		        + "memo=:t.memo,"
		        + "deleteFlag=:t.deleteFlag,"
		        + "billAmount=:t.billAmount,"
		        + "paperCardName=:t.paperCardName,"
		        + "paperName=:t.paperName,"
		        + "inputBeginAt=:t.inputBeginAt,"
		        + "inputEndAt=:t.inputEndAt,"
		        + "months=:t.months,"
		        + "beginAt=:t.beginAt,"
		        + "endAt=:t.endAt,"
		        + "updateUser=:t.updateUser,"
		        + "updateAt=now()"
				+ " WHERE id=:t.id")
    void update(@SQLParam("t") KDCard kDCard);
    
    @SQL("UPDATE KDCard SET deleteFlag=0 WHERE id=:1")
    void deleteById(int id);
}